/**
 * fulihui.com Inc.
 * Copyright (c) 2015-2017 All Rights Reserved.
 */
package com.fulihui.usercore.core.repository.impl;

import com.fulihui.usercore.biz.conv.GeneralConv;
import com.fulihui.usercore.core.repository.LoginHelpRepository;
import com.fulihui.usercore.dal.dataobj.LoginDO;
import com.fulihui.usercore.dal.dataobj.LoginHelpDO;
import com.fulihui.usercore.dal.dataobj.LoginHelpDOExample;
import com.fulihui.usercore.dal.mapper.LoginHelpDOMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Arrays;
import java.util.List;

import static java.util.Collections.emptyList;
import static org.springframework.util.CollectionUtils.isEmpty;

/**
 * @author: zhangyingjie
 * @version: v 0.1 2017年10月25日 17:20  zhangyingjie Exp $
 */
@Repository
public class LoginHelpRepositoryImpl implements LoginHelpRepository {
    @Autowired
    private LoginHelpDOMapper loginHelpDOMapper;
    @Override
    public LoginDO queryByPK(String loginId) {
        return GeneralConv.conv(loginHelpDOMapper.selectByPrimaryKey(loginId),LoginDO.class);
    }

    @Override
    public List<LoginDO> queryByLoginIds(List<String> ids) {
        if (isEmpty(ids)) {
            return emptyList();
        }
        List<LoginDO> loginDOs = Arrays.asList();
        for (String loginId : ids) {
            LoginDO loginDO = this.queryByPK(loginId);
            if (loginDO != null){
                loginDOs.add(loginDO);
            }
        }
        return null;
    }

    @Override
    public boolean delete(String loginid) {
        LoginHelpDOExample example = new LoginHelpDOExample();
        example.createCriteria().andLoginIdEqualTo(loginid);
        return loginHelpDOMapper.deleteByExample(example) > 0;
    }

    @Override
    public boolean insert(LoginHelpDO record) {
        return loginHelpDOMapper.insert(record) > 0;
    }
}
